<template>
  <div>
    <!-- 头部上传图片 --> 
    <div class="topnav" v-if="imglist.length>0">
      <mt-swipe :auto="2000" style="position:relative; height:100%" :showIndicators="hide">
        <mt-swipe-item v-for="item in imglist" :key="item.imageId">
          <img :src="item" style="width:100%; height:100%;" @click="imgbianji()">

          <!-- <div>{{item.imgurl}}</div> -->
        </mt-swipe-item>
        <!-- <mt-swipe-item>
              <img src="http://static.ruitaowang.com/attached/file/20170728/20170728141915_96.jpg" alt="">
        </mt-swipe-item>-->
      </mt-swipe>
      <!-- <div class="navimg" v-show="imglist.length<4"> -->
        <div class="navimg">
        <input type="file" class="topfile" @change="newimg" accept="image/jpg, image/png, image/gif, image/jpeg, image/svg"   multiple>
      </div>
    </div>
    <div v-else style="width:100%;
    height:150px; position:relative;">
         <div class="navimg" style="top:44px; left:43%;">
        <input type="file" class="topfile" @change="newimg" accept="image/jpg, image/png, image/gif, image/jpeg, image/svg"   multiple>
      </div>
    </div>
        <!-- 轮播图详情 -->
      <div class="box_img" v-show="imgbjshow">
       <img src="../../assets/images/1415927.png" alt="" class="top_wancheng" @click="imgwancheng()">
        <img src="../../assets/images/1415926.png" alt="" class="top_delete"  @click="imgdelete()">
       <img :src="topimg_url" alt="" class="topimg" > 
        <img :src="item" alt="" v-for="(item, index) in imglist" :key="item.index" class="lastimg" :class="{active:headid==index}" @click="layimg(index,$event)" >
      </div>
    <!-- 标题 -->
    <!-- <input type="text" placeholder="请输入商品标题" id="goods_text" v-model="goodsName"> -->
    <div class="canshu" style="margin:0">
      <label for="first_in">标题</label>
      <input type="text" id="goods_text" placeholder="输入您的商品标题" v-model="goodsName">
    </div>

    <div class="box_fan">
       <router-link to @click.native="fengmianshow()">
         <span>设置产品封面</span>
         <img :src="imgfengmian" alt="" class="box_fmimg">
          <img src="../../assets/images/前进(进入详情页).png" alt>
       </router-link>
    </div>

      <div v-show="fengmian_sh"  class="fengmian_show"><!--v-show="fengmian_sh"-->
      <div class="fengmian_show_header">
          <h1>设置产品封面</h1>
          <ul>
            <li v-for="(iu, index) in imglist" :key="iu.index"><img :src="iu" :class="{border_img:fengmian_index==index}" @click="Thecover(index,iu)"></li>
          </ul>
          <div class="clearfix"></div>
          <div class="btn_new"><button @click="fengmian_show">取消</button><button @click="Thecover_sub">确定</button></div>
      </div>
      </div>
    <!-- 类目 -->
    <div class="leimu">
      <router-link :to="{path:'/me_leimu',query:{'goodsid':goodsid,'companyid':this.companyid}}" @click.native="itslei">
        <span>类目</span>
        <span style="color:red;">{{lmname}}</span>
        <img src="../../assets/images/前进(进入详情页).png" alt>
      </router-link>
    </div>

    <!-- 输入框 -->
    <div class="canshu" style="border:none">
      <label for="first_in">价格</label>
      <input type="number" id="firstin" placeholder="输入您的产品价格" v-model="goodsScreenPrice">
    </div>
    <div class="ch_next">
      <label for="next_in">库存</label>
      <input type="number" id="next_in" placeholder="输入您的产品库存" v-model="goodsStock">
    </div>
    <div class="ch_last">
      <label for="last_in">运费</label>
      <input type="number" id="last_in" placeholder="输入您的产品运费" v-model="goodsExPrice">
    </div>
      


    
    <div class="miaoshu">
      <router-link :to="{path:'me_goodsmiaoshu',query:{'goodsid':this.goodsid,'companyid':companyid}}" @click.native="miaoshu()">
        <span>商品描述</span>
        <img src="../../assets/images/前进(进入详情页).png" alt>
      </router-link>
    </div>
    <div class="shouhou">
      <span>售后支持</span>
      <mt-switch
        v-model="value"
        style="display:inline; float:right; margin-right:10px; height:32px;"
      ></mt-switch>
    </div>

    <div class="fahuo">
      <router-link to @click.native="dizhi()">
        <span>发货地</span>
        <span style="color:red;">{{cityname}}</span>
        <img src="../../assets/images/前进(进入详情页).png" alt>
      </router-link>
    </div>
    
      <ul class="release-list" >
       <li class="list-li" >
          <span class="left-text">选择产品类型</span>
          <div class="shiwu">
              <span @click="aftersalesClick(0)" :class="{shiwuActive:aftersalesTYPE==0}"></span>
              实物
          </div>
           <div class="feishiwu">
              <span @click="aftersalesClick(1)" :class="{shiwuActive:aftersalesTYPE==1}"></span>
              非实物
          </div>
        </li>
    </ul>
    <div class="bombtn">
      <router-link to @click.native="cangku()">放入仓库</router-link>
      <router-link to @click.native="yulan()">预览商品</router-link>
      <router-link to @click.native="bomfabu()">立即发布</router-link>
    </div>

    <div class="region" v-show="region">
      <div class="regionShow">
        <p class="regionShowP">
          所在地
          <span class="regionclear" @click="regionclear">取消</span>
        </p>
        <div class="anniu">
          <ul>
            <li @click="cityNameClick(currentCity)">
              <img src="../../assets/personal/images/dingyiw.png">
              <span>{{currentCity}}</span>
            </li>
            <li style="background: #fff;">
              <img src="../../assets/personal/images/shuaxin.png">
              <span @click="getwxconfig()">定位</span>
            </li>
          </ul>
        </div>
        <p class="regionShowP">城市</p>
        <div class="erduan">
          <div class="zuobianList">
            <div class="A_Znav">
              <ul>
                <li class="A_ZnavLi">城市定位</li>
                <li style="line-height: 20px;" v-for="(item,ind) in A_zJson" :key="item.name">
                  <a @click="A_ZnavLiClick(ind)">{{item.name}}</a>
                </li>
              </ul>
            </div>
          </div>
          <ul class="listdiqu" v-if="1==listdiqu">
            <div v-for="(itemc,index) in city" :key="index">
              <li
                v-for="(item,ind) in itemc"
                :key="ind"
                @click="cityNameClick(item.name)"
              >{{item.name}}</li>
            </div>
          </ul>
          <ul class="listdiqu" v-else>
            <li
              v-for="(itemc,index) in city"
              :key="index"
              @click="cityNameClick(itemc.name)"
            >{{itemc.name}}</li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { Switch, Swipe, SwipeItem } from "mint-ui";
export default {
  components: {
    [Switch.name]: Switch,
    [Swipe.name]: Swipe,
    [SwipeItem.name]: SwipeItem
  },
  data() {
    return {
      value: false,
      hide: true,
      firstimg: "",
      imglist: [],
      goodsid: "",
      goodsitem: "",
      goodsScreenPrice: "",
      goodsStock: "",
      goodsExPrice: "",
      goodsName: "",
      A_zJson: [
        { name: "A", id: "#A", pinyin: "a" },
        { name: "B", id: "#B", pinyin: "b" },
        { name: "C", id: "#C", pinyin: "c" },
        { name: "D", id: "#D", pinyin: "d" },
        { name: "E", id: "#E", pinyin: "e" },
        { name: "F", id: "#F", pinyin: "f" },
        { name: "G", id: "#G", pinyin: "g" },
        { name: "H", id: "#H", pinyin: "h" },
        { name: "I", id: "#I", pinyin: "i" },
        { name: "J", id: "#J", pinyin: "j" },
        { name: "K", id: "#K", pinyin: "k" },
        { name: "L", id: "#L", pinyin: "l" },
        { name: "M", id: "#M", pinyin: "m" },
        { name: "N", id: "#N", pinyin: "n" },
        { name: "O", id: "#O", pinyin: "o" },
        { name: "P", id: "#P", pinyin: "p" },
        { name: "Q", id: "#Q", pinyin: "q" },
        { name: "R", id: "#R", pinyin: "r" },
        { name: "S", id: "#S", pinyin: "s" },
        { name: "T", id: "#T", pinyin: "t" },
        { name: "U", id: "#U", pinyin: "u" },
        { name: "V", id: "#V", pinyin: "v" },
        { name: "W", id: "#W", pinyin: "w" },
        { name: "X", id: "#X", pinyin: "x" },
        { name: "Y", id: "#Y", pinyin: "y" },
        { name: "Z", id: "#Z", pinyin: "z" }
      ],

      currentCity: "北京",
      region: false,
      listdiqu: 1,
      city: [],
      cityname: "",
      latitude1: "", //纬度39.903230/////37.254329
      longitude1: "", //经度116.397720//////139.693512
      TiTle: "首象共享",
      shuoming: "首象共享！",
      imgfengmian:'',
      fengmian_sh:false,
      fengmian_index:0,
      imgbjshow:false,
      headid:0,
      topimg_url:'',
      contentimg:'',
      entrance:'',
      lmid:'',
      lmname:'',
      msimg:[],
      mstext:'',
      shouhou:'',
      companyid:'',
      aftersalesTYPE:''
    };
  },
  created(){

  },
  mounted() {
    this.info();
    // this.city_list();
    this.auto()
  },
  methods: {
     aftersalesClick:function(type){//支不支持售后
        console.log(type)
        this.aftersalesTYPE=type
      },
    info() {
      // sessionStorage.clear();
      // 编辑页面 接收商品id
     
      // if(this.$route.query.goodsid==''||this.$route.query.goodsid==undefined){
      //   this.goodsid=sessionStorage.getItem('goodsid')
      // }else{
         this.goodsid = this.$route.query.goodsid;
      // }
      console.log('goodsid='+this.goodsid)
     
      // this.msimg=this.$route.query.msimg;
      this.mstext=this.$route.query.mstext;
      
      if(sessionStorage.getItem('zheng')==null){
        this.goodsName=''
      }else{
        this.goodsName=sessionStorage.getItem('zheng')
      }
      if(sessionStorage.getItem('kucun')==null){
        this.goodsStock=''
      }else{
        this.goodsStock=sessionStorage.getItem('kucun')
      }
      if(sessionStorage.getItem('yunfei')==null){
        this.goodsExPrice=''
      }else{
        this.goodsExPrice=sessionStorage.getItem('yunfei')
      }
       if(sessionStorage.getItem('jiage')==null){
        this.goodsScreenPrice=''
      }else{
        this.goodsScreenPrice=sessionStorage.getItem('jiage')
      }
       if(sessionStorage.getItem('fahuo')==null||sessionStorage.getItem('fahuo')==undefined){
        this.cityname=''
      }else{
        this.cityname=sessionStorage.getItem('fahuo')
      }
      
      if(JSON.parse(sessionStorage.getItem('topimg'))==null){
         this.imglist=[]
      }else{
       this.imglist=JSON.parse(sessionStorage.getItem('topimg'));
      }
      console.log(this.imglist)
      // console.log(JSON.parse(localStorage.getItem('topimg')) )
      this.imgfengmian=sessionStorage.getItem('fengmian')
      var hos=sessionStorage.getItem('shouhou')
       this.lmname=this.$route.query.lmname;
         this.lmid=this.$route.query.lmid;
         this.companyid=this.$route.query.companyid
         console.log('companyid='+this.companyid)
         if(this.lmname==''||this.lmname==undefined){
               if(sessionStorage.getItem('leimuname')==null){
                  this.lmname=''
                }else{
                  this.lmname=sessionStorage.getItem('leimuname')
                }
         }
         if(this.lmid==''||this.lmid==undefined){
          if(sessionStorage.getItem('leimuid')==null){
                  this.lmid=''
                }else{
                  this.lmid=sessionStorage.getItem('leimuid')
                }
         }
        
           this.msimg=JSON.parse(sessionStorage.getItem('lastimg')) 
          console.log('msimg='+this.msimg)
         if(this.mstext==''||this.mstext==undefined){
           
           if(sessionStorage.getItem('mstext')==null){
             this.mstext=''
           }else{
             this.mstext=sessionStorage.getItem('mstext')
           }
          
         }
         console.log('mstext='+this.mstext)
      console.log(hos)
      if(hos=='0'){
        this.value=true
      }else{
        this.value=false
      }
      // this.goodsName=storage.a
      console.log(this.goodsName)
     console.log(this.goodsid,this.lmid,this.lmname,this.msimg,this.mstext)
     
      if (
        this.goodsid == 'undefined' ||
        this.goodsid == null ||
        this.goodsid == ""
      ) {
        this.entrance=1
        console.log('entrance='+this.entrance)
      } else {
        this.entrance=2
        //  编辑商品
console.log('entrance='+this.entrance)
        this.$http
          .post(
            this.APIURL_PREFIX + "/api/wap/goodsDetail",
            $.param({ goodsId: this.goodsid })
          )
          .then(response => {
            console.log(response)
            this.goodsitem = response.data;
            this.goodsScreenPrice = this.goodsitem.goods.goodsScreenPrice / 100;
            this.goodsStock = this.goodsitem.goods.goodsStock;
            this.goodsExPrice = this.goodsitem.goods.goodsExPrice/100;
            this.goodsName = this.goodsitem.goods.goodsName;
            this.cityname=this.goodsitem.goods.deliveryPlace
            this.imgfengmian=response.data.goods.goodsThum
            this.contentimg=response.data.albumsUrl
            this.lmname=response.data.goods.cateName
            this.lmid=response.data.goods.cateId
            this.aftersalesTYPE=response.data.goods.isMaterial
              var fengmian=response.data.albumsUrl
                var imgUrls=[]
                fengmian.forEach(element => {
                    imgUrls.push(element.url)
                })
                this.imglist=imgUrls
                 var ous=response.data.detailsAlbumsUrl
                 var hens=[]
                  ous.forEach(element=>{
                     hens.push(element.url)
                  })
                  this.msimg=hens
            console.log(this.imgfengmian)
            console.log(this.imglist);
            if (this.goodsitem.goods.isAfterSale == 0) {
              this.value = true;
            } else {
              this.value = false;
            }
            console.log(this.goodsitem);
          });
      }
    },
    auto(){
  
    },
    //  显示设置封面弹出层
    fengmianshow(){
     console.log(8888)
     if(this.imglist.length<1){
       layer.msg('请先上传商品图片')
     }else{
     this.fengmian_sh=true
     }
     
    },
    // 立即发布商品
    bomfabu(){
      if(this.goodsid==''||this.goodsid==null||this.goodsid==undefined){
       this.goodsid=sessionStorage.getItem('goodsid')
      }
     
      console.log(this.goodsid)
     if(this.goodsid==undefined){
       console.log(686868)
       this.entrance=1
     }else{
       this.entrance=2
     }
     var lodimg=this.msimg.join(',')
     var arrimg=this.imglist.join(',')
      if(this.value==true){
         this.shouhou=0
      }else{
        this.shouhou=1
      }
     console.log(arrimg,this.goodsName,this.imgfengmian,this.goodsScreenPrice,this.goodsStock,this.goodsExPrice,this.cityname,this.lmname,this.lmid,this.shouhou,this.companyid)
     if(this.entrance==1){
       console.log('发布商品')
       if(arrimg.length<1){
         layer.msg('请上传商品图片')
       }else if(this.goodsName==''){
           layer.msg('请填写商品标题')
       }else if(this.lmid==''){
         layer.msg('请选择商品类目')
       }else if(this.goodsScreenPrice==''){
            layer.msg('请填写商品价格')
       }else if(this.cityname==''){
            layer.msg('请选择商品发货地')
       }else if(this.msimg==''){
         layer.msg('请填写商品描述')
       }else
       {
         this.$http
         .post(this.APIURL_PREFIX + "/api/wap/createGoods",
         $.param({goodsThum:this.imgfengmian,isMaterial:this.aftersalesTYPE,cateId:this.lmid,goodsScreenPrice:this.goodsScreenPrice*100,goodsStock:this.goodsStock,goodsExPrice:this.goodsExPrice*100,detaileDescription:this.mstext,isAfterSale:this.shouhou,deliveryPlace:this.cityname,goodsProviderId:this.companyid,goodsOnline:1,goodsName:this.goodsName})
              
         )
         .then(response=>{
           console.log(response)
           var goodsid=response.data.data.goodsId
           if(response.data.code==0){
              this.$http
         .post(this.APIURL_PREFIX + "/api/wap/goodsAlbum/create",
         $.param({imgUrl:arrimg,detailePictureUrl:lodimg,imageType:1,goodsId:goodsid,goodsProviderId:this.companyid}))
            .then(response=>{
              console.log(response)
              if(response.data.code==0){
                 sessionStorage.clear()
                 this.$router.push({name:'me_goods'})
              }
            })
           }
         })
       }
     }else{
       console.log('编辑商品')
       console.log(this.goodsid,arrimg,lodimg,this.imgfengmian,this.lmid,this.cityname,this.goodsName)
            if(arrimg.length<1){
         layer.msg('请上传商品图片')
       }else if(this.goodsName==''){
           layer.msg('请填写商品标题')
       }else if(this.lmid==''){
         layer.msg('请选择商品类目')
       }else if(this.goodsScreenPrice==''){
            layer.msg('请填写商品价格')
       }else if(this.cityname==''){
            layer.msg('请选择商品发货地')
       }else if(this.msimg.length<1){
         layer.msg('请填写商品描述')
       }else
       {
         this.$http
        .put(this.APIURL_PREFIX + "/api/wap/updateGoods",
         $.param({goodsId:this.goodsid,imgUrl:arrimg,detailePictureUrl:lodimg,isMaterial:this.aftersalesTYPE,goodsThum:this.imgfengmian,cateId:this.lmid,goodsScreenPrice:this.goodsScreenPrice*100,goodsStock:this.goodsStock,goodsExPrice:this.goodsExPrice*100,detaileDescription:this.mstext,isAfterSale:this.shouhou,deliveryPlace:this.cityname,goodsOnline:1,goodsName:this.goodsName})
         )
        .then(response => {
             console.log(response)
             if(response.data.code==0){
                  sessionStorage.clear()
                  this.$router.push({name:'me_goods'})
             }
        })
       }
     }
    },
    // 点击放入仓库
    cangku(){
       this.goodsid=sessionStorage.getItem('goodsid')
      console.log(this.goodsid)
     if(this.goodsid==undefined){
       console.log(686868)
       this.entrance=1
     }else{
       this.entrance=2
     }
     console.log('放入仓库')
     var lodimg=this.msimg.join(',')
      var arrimg=this.imglist.join(',')
      if(this.value==true){
         this.shouhou=0
      }else{
        this.shouhou=1
      }
     console.log(arrimg,this.goodsName,this.imgfengmian,this.aftersalesTYPE,this.goodsScreenPrice,this.goodsStock,this.goodsExPrice,this.cityname,this.lmname,this.lmid,this.shouhou,this.companyid)
     if(this.entrance==1){
       console.log('发布商品')
       if(arrimg.length<1){
         layer.msg('请上传商品图片')
       }else if(this.goodsName==''){
           layer.msg('请填写商品标题')
       }else if(this.lmid==''){
         layer.msg('请选择商品类目')
       }else if(this.goodsScreenPrice==''){
            layer.msg('请填写商品价格')
       }else if(this.cityname==''){
            layer.msg('请选择商品发货地')
       }else if(this.msimg==''){
         layer.msg('请填写商品描述')
       }else
       {
         this.$http
         .post(this.APIURL_PREFIX + "/api/wap/createGoods",
         $.param({goodsThum:this.imgfengmian,isMaterial:this.aftersalesTYPE,cateId:this.lmid,goodsScreenPrice:this.goodsScreenPrice*100,goodsStock:this.goodsStock,goodsExPrice:this.goodsExPrice*100,detaileDescription:this.mstext,isAfterSale:this.shouhou,deliveryPlace:this.cityname,goodsProviderId:this.companyid,goodsName:this.goodsName})
              
         )
         .then(response=>{
           console.log(response)
           var goodsid=response.data.data.goodsId
           if(response.data.code==0){
              this.$http
         .post(this.APIURL_PREFIX + "/api/wap/goodsAlbum/create",
         $.param({imgUrl:arrimg,detailePictureUrl:lodimg,imageType:1,goodsId:goodsid,goodsProviderId:this.companyid}))
            .then(response=>{
              console.log(response)
              if(response.data.code==0){
                 sessionStorage.clear()
                 this.$router.push({name:'me_goods'})
              }
            })
           }
         })
       }
     }else{
       console.log('编辑商品')
            if(arrimg.length<1){
         layer.msg('请上传商品图片')
       }else if(this.goodsName==''){
           layer.msg('请填写商品标题')
       }else if(this.lmid==''){
         layer.msg('请选择商品类目')
       }else if(this.goodsScreenPrice==''){
            layer.msg('请填写商品价格')
       }else if(this.cityname==''){
            layer.msg('请选择商品发货地')
       }else if(this.msimg==''){
         layer.msg('请填写商品描述')
       }else
       {
         this.$http
        .put(this.APIURL_PREFIX + "/api/wap/updateGoods",
         $.param({goodsId:this.goodsid,imgUrl:arrimg,isMaterial:this.aftersalesTYPE,detailePictureUrl:lodimg,goodsThum:this.imgfengmian,cateId:this.lmid,goodsScreenPrice:this.goodsScreenPrice*100,goodsStock:this.goodsStock,goodsExPrice:this.goodsExPrice*100,detaileDescription:this.mstext,isAfterSale:this.shouhou,deliveryPlace:this.cityname,goodsName:this.goodsName,goodsOnline:0})
         )
        .then(response => {
             console.log(response)
             if(response.data.code==0){
                  sessionStorage.clear()
                  this.$router.push({name:'me_goods'})
             }
        })
       }
     }

    },
    // 预览商品
    yulan(){
              if(this.imglist.length<1){
         layer.msg('请上传商品图片')
       }else if(this.goodsName==''){
           layer.msg('请填写商品标题')
       }else if(this.lmid==''){
         layer.msg('请选择商品类目')
       }else if(this.goodsScreenPrice==''){
            layer.msg('请填写商品价格')
       }else if(this.cityname==''){
            layer.msg('请选择商品发货地')
       }else if(this.msimg.length<1){
         layer.msg('请填写商品描述')
       }else
       {
      console.log(8888)
          if(this.value==true){
         this.shouhou=0
      }else{
        this.shouhou=1
      }
            sessionStorage.setItem('leimuid',this.lmid)
            sessionStorage.setItem('newshi',this.aftersalesTYPE)
            sessionStorage.setItem('leimuname',this.lmname)
            sessionStorage.setItem('zheng', this.goodsName);
            sessionStorage.setItem('topimg',JSON.stringify(this.imglist));
            sessionStorage.setItem('jiage',this.goodsScreenPrice)
            sessionStorage.setItem('kucun',this.goodsStock)
            sessionStorage.setItem('yunfei',this.goodsExPrice)
            sessionStorage.setItem('fahuo',this.cityname)
            // sessionStorage.setItem('msimg',this.msimg)
    sessionStorage.setItem('mstext', this.mstext)
            console.log(this.imgfengmian)
            sessionStorage.setItem('fengmian',this.imgfengmian)
            if(this.value==true){
               sessionStorage.setItem('shouhou',0)
            }else{
               sessionStorage.setItem('shouhou',1) 
            }

     this.$router.push({path:'me_goodsyulan',query:{goodsid:this.goodsid, aftersalesTYPE:this.aftersalesTYPE,companyid:this.companyid, goodsName:this.goodsName,imgfengmian:this.imgfengmian,lmid:this.lmid,goodsScreenPrice:this.goodsScreenPrice,goodsstock:this.goodsStock,goodsexprice:this.goodsExPrice,mstext:this.mstext,shouhou:this.shouhou,cityname:this.cityname,entrance:this.entrance}})
    }
    },
    // 设置封面图片点击
   Thecover(index,u){
     this.fengmian_index=index
     this.imgfengmian=u
   },
  //  设置封面取消
   fengmian_show(){
     this.fengmian_sh=false
   },
  //  设置封面确定
   Thecover_sub(){
    console.log(this.imglist)
     this.imglist.splice(this.fengmian_index,1)
      this.imglist.unshift(this.imgfengmian)
       this.fengmian_sh=!this.fengmian_sh
        this.fengmian_index=0;
   },
  //  点击显示选择地址弹出层
    dizhi() {
       this.listdiqu=1
      this.region = true;
      this.city_list()
     
    },
    // 点击轮播图图片
    layimg(id,vm){ 
        console.log(id)
        console.log(vm.target)
       this.headid=id
       console.log(this.headid,id)
       var topurl=$(vm.target).attr('src')
       
        this.topimg_url=topurl
    },
    itslei(){
          if(this.goodsid!==''&&this.goodsid!==undefined&&this.goodsid!==null){
             sessionStorage.setItem('goodsid',this.goodsid)
          }
              sessionStorage.setItem('newshi',this.aftersalesTYPE)
            sessionStorage.setItem('leimuid',this.lmid)
            sessionStorage.setItem('leimuname',this.lmname)
            sessionStorage.setItem('zheng', this.goodsName);
            sessionStorage.setItem('topimg',JSON.stringify(this.imglist));
            sessionStorage.setItem('jiage',this.goodsScreenPrice)
            sessionStorage.setItem('kucun',this.goodsStock)
            sessionStorage.setItem('yunfei',this.goodsExPrice)
            sessionStorage.setItem('fahuo',this.cityname)
            // sessionStorage.setItem('msimg',this.msimg)
            sessionStorage.setItem('mstext', this.mstext)
            console.log(this.imgfengmian)
            sessionStorage.setItem('fengmian',this.imgfengmian)
            if(this.value==true){
               sessionStorage.setItem('shouhou',0)
            }else{
               sessionStorage.setItem('shouhou',1) 
            }
    },
      miaoshu(){
        console.log(this.lmid)
        if(this.goodsid!==''&&this.goodsid!==undefined&&this.goodsid!==null){
             sessionStorage.setItem('goodsid',this.goodsid)
          }
           sessionStorage.setItem('newshi',this.aftersalesTYPE)
            sessionStorage.setItem('leimuid',this.lmid)
            sessionStorage.setItem('leimuname',this.lmname)
            sessionStorage.setItem('zheng', this.goodsName);
            sessionStorage.setItem('topimg',JSON.stringify(this.imglist));
            sessionStorage.setItem('jiage',this.goodsScreenPrice)
            sessionStorage.setItem('kucun',this.goodsStock)
            sessionStorage.setItem('yunfei',this.goodsExPrice)
            sessionStorage.setItem('fahuo',this.cityname)
            // sessionStorage.setItem('msimg',this.msimg)
    sessionStorage.setItem('mstext', this.mstext)
            console.log(this.imgfengmian)
            sessionStorage.setItem('fengmian',this.imgfengmian)
            if(this.value==true){
               sessionStorage.setItem('shouhou',0)
            }else{
               sessionStorage.setItem('shouhou',1) 
            }
            
      },
    
    // 选择地址
    A_ZnavLiClick(id) {
      this.city = [];
      console.log(id);
      this.listdiqu = 2;
      this.$http
        .get(this.APIURL_PREFIX + "/api/wap/districts/city")
        .then(response => {
          this.city = response.data.data[id];
          console.log(this.city);
          // this.city_list()
        })
        .catch(function(err) {
          console.log(err);
        });
    },
     imgbianji(){
            console.log('编辑')
            this.imgbjshow=true
            this.topimg_url=this.imglist[0]
          },
        imgwancheng(){
          this.imgbjshow=false
              console.log('完成')
        },
        imgdelete(){
          console.log(this.headid)
            let vm = this;
          if(confirm("确定删除该图片？")){
          vm.imglist.splice(this.headid, 1);
          this.topimg_url=this.imglist[0]
        }
        },
    regionclear() {
      this.region = false;
      this.listdiqu = 1;
      this.city_list();
    },
    cityNameClick(name) {
      console.log(name);
      //  this.city_list()
      this.cityname = name;
      this.region = false;
      this.city_list()
    },
    city_list() {
      //地区接口
      console.log('地区接口')
      this.$http
        .get(this.APIURL_PREFIX + "/api/wap/districts/city")
        .then(response => {
          this.city = response.data.data;
        })
        .catch(function(err) {
          console.log(err);
        });
    },
    getwxconfig() {
      var vm = this;
      this.$http
        .get(
          this.APIURL_PREFIX +
            "/api/wxs/config?url=" +
            escape(location.href.split("#")[0])
        )
        .then(response => {
          console.log(response.data);
          var appid = "wx488ae3f57360b7ea";
          wx.config({
            debug: false,
            appId: appid,
            timestamp: response.data.data.timestamp,
            nonceStr: response.data.data.noncestr,
            signature: response.data.data.signature,
            jsApiList: [
              "onMenuShareTimeline",
              "onMenuShareAppMessage",
              "onMenuShareQQ",
              "onMenuShareWeibo",
              "onMenuShareQZone",
              "scanQRCode",
              "getLocation"
            ]
          });
         
          wx.ready(function() {
            wx.getLocation({
              type: "gcj02", // 默认为wgs84的gps坐标，如果要返回直接给openLocation用的火星坐标，可传入'gcj02'
              success: function(res) {
                var latitude = res.latitude; // 纬度，浮点数，范围为90 ~ -90
                var longitude = res.longitude;
                console.log(latitude, longitude);
                var exp = undefined;
                if (exp == vm.Var_city) {
                  vm.latitude1 = latitude;
                  vm.longitude1 = longitude;
                  vm.map();
                } else {
                  vm.latitude1 = vm.Var_lat;
                  vm.longitude1 = vm.Var_lon;
                  vm.currentCity = vm.Var_city;
                }
              },
              fail: function() {
                //失败
                vm.msg = "失败";
              }
            });
            wx.onMenuShareTimeline({
              title: vm.TiTle,
              link:
                "http://" +
                window.location.host +
                "/wap/wx/login?fk=1-35-" +
                localStorage.headid +
                "-no",
              desc: vm.shuoming,
              imgUrl:
                "http://static.ruitaowang.com/attached/file/2018/11/06/20181106144126178.jpg",
              success: function() {},
              cancel: function() {}
            });
            wx.onMenuShareAppMessage({
              title: vm.TiTle,
              link:
                "http://" +
                window.location.host +
                "/wap/wx/login?fk=1-35-" +
                localStorage.headid +
                "-no",
              desc: vm.shuoming,
              imgUrl:
                "http://static.ruitaowang.com/attached/file/2018/11/06/20181106144126178.jpg",
              success: function() {},
              cancel: function() {}
            });
            wx.onMenuShareQQ({
              title: vm.TiTle,
              link:
                "http://" +
                window.location.host +
                "/wap/wx/login?fk=1-35-" +
                localStorage.headid +
                "-no",
              desc: vm.shuoming,
              imgUrl:
                "http://static.ruitaowang.com/attached/file/2018/11/06/20181106144126178.jpg",
              success: function() {},
              cancel: function() {}
            });
            wx.onMenuShareWeibo({
              title: vm.TiTle,
              link:
                "http://" +
                window.location.host +
                "/wap/wx/login?fk=1-35-" +
                localStorage.headid +
                "-no",
              desc: vm.shuoming,
              imgUrl:
                "http://static.ruitaowang.com/attached/file/2018/11/06/20181106144126178.jpg",
              success: function() {},
              cancel: function() {}
            });
            wx.onMenuShareQZone({
              title: vm.TiTle,
              link:
                "http://" +
                window.location.host +
                "/wap/wx/login?fk=1-35-" +
                localStorage.headid +
                "-no",
              desc: vm.shuoming,
              imgUrl:
                "http://static.ruitaowang.com/attached/file/2018/11/06/20181106144126178.jpg",
              success: function() {},
              cancel: function() {}
            });
          });
        });
    },
    map() {
      var vm = this;
      var geocoder = new qq.maps.Geocoder({
        complete: function(result) {
          //解析成功的回调函数
          console.log(result.detail);
          var address_city = result.detail.addressComponents.city; //市
          vm.currentCity = address_city;
          console.log("微信获取当前城市:", vm.currentCity);
          // vm.loadMore();
        }
      });
      geocoder.getAddress(new qq.maps.LatLng(this.latitude1, this.longitude1));
    },
    newimg:function(e, targetparam) {
      console.log('上传图片')
          var files = e.target.files || e.dataTransfer.files;
           console.log(targetparam);
      console.log(files, e);
      console.log(this[targetparam]);
      this.createImage(files,e,targetparam)
    },
    createImage(file, e, targetparam) {
           let vm = this;
      lrz(file[0], { width: 480 })
        .then(function(rst) {
          vm.$http({
            url: vm.APIURL_PREFIX + "/uploadForCertificate",
            method: "post",
            data: rst.formData
          })
            .then(response => {
                  console.log(response)
                  var hrefimg=response.data.msg
                  vm.imglist.push(hrefimg)
                  console.log('封面='+vm.imgfengmian)
                  if(vm.imgfengmian==''||vm.imgfengmian==null){
                    vm.imgfengmian=hrefimg
                  }
            })
        })
    },
   
  },
  //  beforeRouteLeave( to, from,next){
  //     if (to.name == 'me_goods') {
  //           console.log("测试")
  //           to.meta.isUseCache = true;
  //       }else if(to.name == 'Seach'){
  //           console.log("Seach")
  //           to.meta.isUseCache = true;
  //       } else if (to.name=='Commodity'){
  //           console.log("Commodity")
  //           to.meta.isUseCache = true;
  //       }
  //       next();
  //  }
};
</script>

<style scoped>
@import "../../assets/personal/css/me_newgoods.css";
</style>
